/**
* All Rights Reserved , Copyright (C) 2020 , 青岛鼎信通讯股份有限公司
*
* SdMilePostTemplateService
* 里程碑模板
*
* 修改纪录
* 2020-12-25 版本：1.0 lanjianwei 创建。
* @version 版本：1.0
* @author 作者：lanjianwei
* 创建日期：2020-12-25
*/
package com.topscomm.gpm.service.impl;

import com.alibaba.fastjson.JSONArray;
import com.topscomm.basic.BasicEntity;
import com.topscomm.basic.exception.ServiceException;
import com.topscomm.basic.util.PrimaryKeyUtil;
import com.topscomm.pub.util.ConvertUtil;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;

import com.topscomm.gpm.service.IGpmMilePostTemplateService;
import com.topscomm.gpm.service.impl.auto.GpmMilePostTemplateServiceAuto;

import java.util.Map;

@Service(value = "gpmMilePostTemplateService")
@Scope(value = "singleton")
public class GpmMilePostTemplateService extends GpmMilePostTemplateServiceAuto implements IGpmMilePostTemplateService {

    @Override
    protected void beforeInsert(BasicEntity entity) throws ServiceException {
        if (entity.getId() <= 0) {
            long[] arrayId = PrimaryKeyUtil.GeneIDs(entity.getTableName(), 1);
            entity.setId(arrayId[0]);
        }
    }
    /**
     * @description:
     * @author xinfushuo
     * @param
     * @return
     * @date 2021/10/18
     * @modify
     */
    @Override
    protected void updateBefore(Map<String,Object> map) {
        // 对项目级别做处理
        JSONArray levelArray = JSONArray.parseArray(map.get("projectlevel").toString());
        StringBuffer sb = new StringBuffer();
        for(int i=0;i<levelArray.size();i++){
            String level = levelArray.get(i).toString();
            if(i==levelArray.size()-1){
                sb.append(level);
            }else{
                sb.append(level + ",");
            }
        }
        map.replace("projectlevel", ConvertUtil.convertToString(sb));
    }
}
